package Acm;


import java.util.Scanner;
public class AClosestCitiesOther {
    static Scanner scanner = new Scanner(System.in);
    public static void main(String[] args) {
        int n=scanner.nextInt();
        for (int i = 0; i < n; i++) {
            solve();
        }
    }
    public static void solve() {

        int n = scanner.nextInt();
        Integer[] v=new Integer[n];
        for (int i = 0; i < n; i++) {
            int tmp=scanner.nextInt();
            v[i]=tmp;
        }
        int[] flag = new int[n];
        flag[n - 1] = 1;
        for (int i = 1; i < n - 1; i++) {
            if ((v[i] - v[i-1]) > (v[i+1] - v[i])) {
                flag[i] = 0;
            } else {
                flag[i] = 1;
            }
        }
        int[] a=new int[n];
        int[] b=new int[n];
        for (int i = 1; i < n; i++) {
            if (flag[i - 1] == 0) {
                a[i]=a[i-1] + 1;
            } else {
                a[i]=a[i-1]+v[i]-v[i-1];
            }
        }
        for (int i = n - 2; i >= 0; i--) {
            if (flag[i + 1] == 1) {
                b[i]=b[i+1]+1;
            } else {
                b[i]=b[i+1]+v[i+1]-v[i];
            }
        }
        int q = scanner.nextInt();
        while (q-- > 0) {
            int x = scanner.nextInt();
            int y = scanner.nextInt();
            x--;
            y--;
            if (x < y) {
                System.out.println(a[y] - a[x]);
            } else {
                System.out.println(b[y] - b[x]);
            }
        }
    }
}
